/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021.
 * Description: header for ubi device maintenance.
 * Author: liangfangping
 * Create: 2021-05-07
 */

#ifndef RTOS_UBI_DEBUG_H
#define RTOS_UBI_DEBUG_H

/* UBI enhance messages */
#ifdef CONFIG_RTOS_UBIFS_MAINTENANCE_ENHANCE
#include "ubi.h"

#ifdef CONFIG_RTOS_UBIFS_KBOX
/* This func print ubi_num, vol_id, pid and error message */
#define rtos_ubi_err(ubi, cond, fmt, ...)				\
	do {							\
		if (cond) {					\
			int kbox_ret;				\
			kbox_ret = set_kbox_region(get_flash_kbox_id()); \
			pr_err("UBI_ERR ubi %d %s:%d " fmt "\n",	\
				ubi->ubi_num, __func__,	\
				__LINE__, ##__VA_ARGS__);	\
			restore_kbox_region(kbox_ret);		\
		}						\
	} while (0)
/* This func not print ubi_num, vol_id, pid */
#define rtos_ubi_err_noc(cond, fmt, ...)				\
	do {							\
		if (cond) {					\
			int kbox_ret;				\
			kbox_ret = set_kbox_region(get_flash_kbox_id()); \
			pr_err("UBI_ERR %s:%d " fmt "\n",		\
				__func__, __LINE__, ##__VA_ARGS__);	\
			restore_kbox_region(kbox_ret);		\
		}						\
	} while (0)
/* This func print ubifs message */
#define rtos_ubi_msg(fmt, ...)				\
	do {							\
		int kbox_ret;					\
		kbox_ret = set_kbox_region(get_flash_kbox_id());	\
		pr_notice("UBI_MSG %s:%d " fmt "\n",			\
			__func__, __LINE__, ##__VA_ARGS__);		\
		restore_kbox_region(kbox_ret);			\
	} while (0)
#else
/* This func print ubi_num, vol_id, pid and error message */
#define rtos_ubi_err(ubi, cond, fmt, ...)				\
	do {							\
		if (cond) {					\
			pr_err("UBI_ERR ubi %d  %s:%d " fmt "\n",      \
				ubi->ubi_num, __func__,		\
				__LINE__, ##__VA_ARGS__);	\
		}						\
	} while (0)
/* This func not print ubi_num, vol_id, pid */
#define rtos_ubi_err_noc(cond, fmt, ...)				\
	do {							\
		if (cond) {					\
			pr_err("UBI_ERR %s:%d " fmt "\n",      \
				__func__, __LINE__, ##__VA_ARGS__);	\
		}						\
	} while (0)
/* This func print ubifs message */
#define rtos_ubi_msg(fmt, ...)				\
	pr_notice("UBI_MSG %s:%d " fmt "\n",			\
		__func__, __LINE__, ##__VA_ARGS__)
#endif /* end of CONFIG_RTOS_UBIFS_KBOX */
#else
#define rtos_ubi_err(ubi, cond, fmt, ...)
#define rtos_ubi_err_noc(cond, fmt, ...)
#define rtos_ubi_msg(fmt, ...)
#endif /* end of CONFIG_RTOS_UBIFS_MAINTENANCE_ENHANCE */
#endif /* end of RTOS_UBI_DEBUG_H */
